﻿using RandomMobileNumber.Models;
using Report;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Documents;

namespace RandomMobileNumber.Reporter
{
    public class SoldRender : IDocumentRenderer
    {
        public void Render(FlowDocument doc, object data)
        {
            //doc.Tag;
            TableRowGroup group = doc.FindName("rowsDetails") as TableRowGroup;
            Style styleCell = doc.Resources["BorderedCell"] as Style;
            foreach (Number item in (ObservableCollection<Number>)data)
            {
                TableRow row = new TableRow();

                TableCell cell = new TableCell(new Paragraph(new Run(item.number)));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                cell = new TableCell(new Paragraph(new Run(item.IsGoodNumber.Equals(1) ? "是" : "否")));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                cell = new TableCell(new Paragraph(new Run(item.cost.ToString())));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                cell = new TableCell(new Paragraph(new Run(item.manName)));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                cell = new TableCell(new Paragraph(new Run(item.manId)));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                cell = new TableCell(new Paragraph(new Run(item.manPhone)));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                var date = Convert.ToDateTime(item.soldDate).ToShortDateString();
                cell = new TableCell(new Paragraph(new Run(date)));
                cell.Style = styleCell;
                row.Cells.Add(cell);

                group.Rows.Add(row);
            }
        }
    }
}
